package com.xcl.service.impl;

import com.xcl.mapper.CentreMapper;
import com.xcl.mapper.XclWaybillMapper;
import com.xcl.service.WaybillServiceInter;
import com.zzg.entity.*;
import com.zzg.util.UuidUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * @ClassName WaybillServiceImpl
 * @Description 运单管理服务层实现类
 * @Author: xiaochaolei
 * @date 2021/6/21 14:51
 * @Version 1. 0
 */
@Service
public class WaybillServiceImpl implements WaybillServiceInter {
    @Autowired
    XclWaybillMapper waybillMapper;

    @Autowired
    CentreMapper centreMapper;


    /**
     * 新增运单管理
     * @param waybill 运单信息
     * @return 影响的行数
     */
    @Override
    public int insertWaybill(Waybill waybill) {
        return  waybillMapper.insertWaybill(waybill);
    }


    /**
     * 查询运单信息
     * @param id 托运单号
     * @return 托运单信息
     */
    @Override
    public Waybill getWaybillById(String id) {
        Waybill waybill=waybillMapper.getWaybillById(id);
        return waybill;
    }


    /**
     * 新增地区信息
     * @param tmsRegion 地区信息
     * @return 影响行数
     */
    @Override
    public int insertTmsRegion(TmsRegion tmsRegion) {
        return waybillMapper.insertTmsRegion(tmsRegion);
    }


    /**
     * 查询有的分站
     * @return 分站集合
     */
    @Override
    public List<Substation> getAllSubstation() {
        return waybillMapper.getAllSubstation();
    }



    /**
     * 新增收货人
     * @param consigner 收货人信息
     * @return 影响行数
     */
    @Override
    public int insertConsigner(Consigner consigner) {
        return  waybillMapper.insertConsigner(consigner);
    }


    /**
     * 新增收货人
     * @param consignee 收货人信息
     * @return 影响行数
     */
    @Override
    public int insertConsignee(Consignee consignee) {
        return waybillMapper.insertConsignee(consignee);
    }

    /**
     * 新增货运
     * @param freightinformationTable 货运信息
     * @return 影响行数
     */
    @Override
    public int insertFreightinformation(FreightinformationTable freightinformationTable) {
        return waybillMapper.insertFreightinformation(freightinformationTable);
    }


    @Override
    public List<String> getAllConsigneeByClientname() {
        List<String> list=new ArrayList<>();
        List<Consignee> allConsigneeByClientname = waybillMapper.getAllConsigneeByClientname();
        for (int i = 0; i < allConsigneeByClientname.size(); i++) {
            list.add( allConsigneeByClientname.get(i).getClientname()+"(编号"+ allConsigneeByClientname.get(i).getConsigneeId()+")");
        }
        return list;
    }

    @Override
    public List<String> getAllConsigneeByPhone() {
        List<String> list=new ArrayList<>();
        List<Consignee> allConsigneeByClientname =waybillMapper.getAllConsigneeByForwardingUnit();
        for (int i = 0; i < allConsigneeByClientname.size(); i++) {
            list.add( allConsigneeByClientname.get(i).getForwardingunit()+"(编号"+ allConsigneeByClientname.get(i).getConsigneeId()+")");
        }
        return list;
    }

    @Override
    public Consignee getAllConsigneeByConsigneeId(String consigneeId) {
        return waybillMapper.getAllConsigneeByConsigneeId(consigneeId);
    }

    @Override
    public List<String> getAllConsignerByClientname() {
        List<String> list=new ArrayList<>();
        List<Consigner> allConsigneeByClientname =waybillMapper.getAllConsignerByClientname();
        for (int i = 0; i < allConsigneeByClientname.size(); i++) {
            list.add( allConsigneeByClientname.get(i).getClientname()+"（编号"+ allConsigneeByClientname.get(i).getConsignerId()+")");
        }
        return list;
    }

    @Override
    public List<String> getAllConsignerByPhone() {
        List<String> list=new ArrayList<>();
        List<Consigner> allConsigneeByClientname =waybillMapper.getAllConsignerByForwardingUnit();
        for (int i = 0; i < allConsigneeByClientname.size(); i++) {
            list.add(allConsigneeByClientname.get(i).getForwardingunit()+"（编号"+ allConsigneeByClientname.get(i).getConsignerId()+")");
        }
        return list;
    }

    @Override
    public Consigner getAllConsignerByConsignerId(String consignerId) {
        return waybillMapper.getAllConsignerByConsignerId(consignerId);
    }

    @Override
    public TmsRegion isExistConsignerArea(String area) {
        return waybillMapper.isExistConsignerArea(area);
    }

    @Override
    public Consigner isExistConsigner(Consigner consigner) {
        return waybillMapper.isExistConsigner(consigner);
    }

    @Override
    public Consignee isExistConsignee(Consignee consignee) {
        return waybillMapper.isExistConsignee(consignee);
    }

    @Override
    public int amendConsigner(Consigner consigner) {
        return waybillMapper.amendConsigner(consigner);
    }

    @Override
    public int amendConsigne(Consignee consignee) {
        return waybillMapper.amendConsigne(consignee);
    }

    @Override
    public int insertWaybillState(String waybillstate) {
        Waybillstate state=new Waybillstate();
        state.setWaybillstateId(UuidUtil.getUuid());
        state.setWaybillId(waybillstate);
        state.setState("未装载");
        return waybillMapper.insertWaybillState(state);
    }

    @Override
    public int insertCostbreakdown(Costbreakdown costbreakdown) {
        return centreMapper.insertCostbreakdown(costbreakdown);
    }

    @Override
    public int insertFinance(Finance finance) {
        return centreMapper.insertFinance(finance);
    }

    @Override
    public Costbreakdown getCostbreakdownById(String id) {
        return centreMapper.getCostbreakdownById(id);
    }

}
